home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
lang_c
/
mscheap2
/
dbugdemo.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-03-13
|
1KB
|
48 lines
//
// Copyright (c) 1990 by Optimal Software, All Rights Reserved
//
//
// A demonstration of the debug functions in the replacement heap manager
//
// We allocate a bunch of blocks and then trigger a diagnostic dump by
// overwriting the end of a block
//
#if !defined( _HEAPDEBUG ) && !defined( _HEAPTRACE )
#define _HEAPDEBUG stdout /* in place of a compiler switch */
#endif
#include <stdio.h>
#include <stdlib.h>
#include <heap.h>
void main()
{
char far *ptr;
int index;
_heappad = 8; /* set the safety margin */
for ( index=1 ; index<=10 ; index++ )
{
ptr = _fmalloc( 100 ); /* these will share the same debug info */
_fheapwatch( ptr, 1 ); /* declare them as read-only */
}
srand(12345);
for ( index=1 ; index<=10 ; index++ )
_fmalloc ( rand() % 1000 ); /* these will be unique */
ptr = _fmalloc(8); /* so will this */
ptr[-1] = 0; /* overwrite the safety margin */
_fmalloc( 8 ); /* this should detect the error */
}